package com.jokins.admin;


import com.jokins.admin.config.sql.SshTunnelUtil;
import lombok.extern.slf4j.Slf4j;
import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.core.task.TaskExecutor;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;

@Slf4j
@Configuration
@EnableCaching
@SpringBootApplication
@MapperScan("com.jokins.admin.*.*.mapper")
@ComponentScan(basePackages = {"com.jokins.*"})
public class LikeProjectApplication {

    public static void main(String[] args) {
        try {
            SshTunnelUtil.createTunnel();
            SpringApplication.run(LikeProjectApplication.class, args);
            log.info("正在运行中.....（づ￣3￣）づ╭❤～");
        } catch (Exception e) {
            SshTunnelUtil.closeTunnel();
            e.printStackTrace();
        }
    }


    @Primary
    @Bean
    public TaskExecutor primaryTaskExecutor() {
        ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
        // 核心线程数
        executor.setCorePoolSize(10);
        // 最大线程数
        executor.setMaxPoolSize(50);
        // 任务队列
        executor.setQueueCapacity(1000);
        // 线程最大存活时间
        executor.setKeepAliveSeconds(60);
        return executor;
    }
}
